package cn.itcast.itcaststore.web.servlet.manager;

import cn.itcast.itcaststore.domain.Notice;
import cn.itcast.itcaststore.serive.NoticeService;
import cn.itcast.itcaststore.serive.impl.NoticeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 查看公告数据回显
 */
@WebServlet("/admin/FindByIdNoticeServlet")
public class FindByIdNoticeServlet extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        NoticeService nService = new NoticeServiceImpl();
        //获取公告id
        int n_id = Integer.parseInt(req.getParameter("id"));
        System.out.println(n_id);
        Notice notice = null;
        try {
            notice = nService.findNoticeById(n_id);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        req.setAttribute("n", notice);

        req.getRequestDispatcher("/admin/notices/edit.jsp").forward(req, resp);
    }
}
